// 抽象工厂方法

var VehicleFactory = function(subType,superType){
    // 判断工厂中是否具有抽象类
    if (typeof VehicleFactory[superType] ==='function'){
        // 缓存类
        function F(){};
        // 继承父类属性和方法
        F.prototype = new VehicleFactory[superType]();
        // 子类 constator 指向子类
        subType.constructor = subType;
        // 子类的原型继承父类
        subType,prototype = new F();
    } else {
        throw new Error('未创建该抽象类')
    }
};

// car abstract class 

VehicleFactory.car  = function (){
    this.type = 'car';
};

VehicleFactory.car.prototype = {
    getPrice : function(){
        return new Error('抽象方法不能调用');
    },
    getSpeed : function(){
        return new Error('抽象方法不能调用');
    }
};
// bus abstract class 

VehicleFactory.Bus  = function (){
    this.type = 'bus';
};

VehicleFactory.bus.prototype = {
    getPrice : function(){
        return new Error('抽象方法不能调用');
    },
    getPassengerNumber : function(){
        return new Error('抽象方法不能调用');
    }
};

// truck abstract class 

VehicleFactory.Truck  = function (){
    this.type = 'truck';
};

VehicleFactory.truck.prototype = {
    getPrice : function(){
        return new Error('抽象方法不能调用');
    },
    getTrainload : function(){
        return new Error('抽象方法不能调用');
    }
};


// implent  and using 

var BMW = function (price,speed) {
    this.price = price;
    this.speed = speed;  
}

VehicleFactory(BMW,'Car');
BMW.prototype.getPrice = function(){
    return this.price;
}
BMW.prototype.getSpeed = function() {
    return this.speed;
};


//兰博基尼子类

var Lamborghini = function(price,speed){
    this.price = price;
    this.speed = speed;
}

VehicleFactory(Lamborghini,'car');
Lamborghini.prototype.getPrice = function(){
    return this.price;
};
Lamborghini.prototype.getSpeed = function(){
    return this.speed
}

// YUtong class 

var Yuton = function(peice,passengers){
    this.price = price;
    this.passengers = passengers;
}

VehicleFactory(Yuton,'Bus')

Yuton.prototype.getPrice = function(){
    return this.price
}
Yuton.prototype.getPassengerNumber = function(){
    return this.passengers
}
// Benztruck class 

var Benztruck = function (peice, trainload) {
    this.price = price;
    this.trainload = trainload;
}

VehicleFactory(Benztruck, 'Bus')

Benztruck.prototype.getPrice = function () {
    return this.price
}
Benztruck.prototype.getTrainload = function () {
    return this.trainload
}
